package com.qiantu.phone.widget.setting;

import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hjq.base.DensityUtils;
import com.hjq.widget.layout.SettingBar;
import com.qiantu.api.entity.DeviceBean;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.app.AppApplication;
import com.qiantu.phone.ui.activity.FirmwareUpdateActivity;

import static android.util.TypedValue.COMPLEX_UNIT_PX;

public class DeviceSettingUpgrade extends SettingBar implements View.OnClickListener {
    private DeviceBean mDevice;
    private AppActivity mContext;
    public DeviceSettingUpgrade(AppActivity context, DeviceBean deviceBean) {
        this(context, null, deviceBean);
    }

    public DeviceSettingUpgrade(AppActivity context, AttributeSet attrs, DeviceBean deviceBean) {
        this(context, attrs, 0, deviceBean);
    }

    public DeviceSettingUpgrade(AppActivity context, AttributeSet attrs, int defStyleAttr, DeviceBean deviceBean) {
        this(context, attrs, defStyleAttr, R.style.setting_item_style, deviceBean);
    }

    public DeviceSettingUpgrade(@NonNull AppActivity context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes, DeviceBean deviceBean) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mDevice = deviceBean;
        mContext = context;
        setLeftText(R.string.firmware_update);
        setRightText(mDevice.getVersion());
        setRightTextColor(AppApplication.getInstance().getThemeColor(R.attr.textColor2));
        setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        setRightTextSize(COMPLEX_UNIT_PX, DensityUtils.dip2px(context, 12));
        setOnClickListener(this::onClick);
    }

    @Override
    public void onClick(View v) {
        FirmwareUpdateActivity.start(mContext, mDevice.getDeviceSerialNo(), 1);
    }
}
